package leetcode_core.leetcode_5;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月09日 21:40
 */
public class MinArray2 {
    public int minArray(int[] numbers) {
        if(numbers[0]<numbers[numbers.length-1]){
            return numbers[0];
        }
        int l = 0, r = numbers.length-1;
        while (l<r){
            if(numbers[l] < numbers[r]){
                return numbers[l];
            }
            int mid = l + ((r-l)>>1);
            if(numbers[l] == numbers[mid]){
                l++;
            }else if(numbers[l] > numbers[mid]){//mid在右数组
                r = mid;
            }else if(numbers[l] < numbers[mid]){
                l = mid+1;
            }
        }
        return numbers[l];
    }
}
